package gameEngine;
import java.io.*;
import java.util.Scanner;
import java.net.Socket;


public class TexasSender {
	public static void main(String[] args) {
		Socket s = null;
		try {
			s = new Socket("", 1432);
			Scanner in = new Scanner(System.in);
			PrintWriter writer = new PrintWriter(s.getOutputStream());
			System.out.println("Connection to " + "192.168.0.1" + " is open");
			String cont = "";
			while (!cont.matches("n.*")) {
				StringBuilder msg = new StringBuilder();
				System.out.println("Begin message; type ! by itself when done");
				String line = in.nextLine();
				while (!line.equals("!")) {
					msg.append(line);
					msg.append("\n");
					line = in.nextLine();
				}

				writer.print(msg);
				writer.flush();
				System.out.println("message sent; awaiting response...");

				BufferedReader responses = 
						new BufferedReader
						(new InputStreamReader(s.getInputStream()));
				while (!responses.ready()){}
				while (responses.ready()) {
					System.out.println(responses.readLine());
				}

				System.out.print("Another message? ");
				cont = in.nextLine();
			}
		} catch (IOException ioe) {
			ioe.printStackTrace();
		} finally {
			try {
				if (s != null) {s.close();}
			} catch (IOException ioe) {
				System.out.println("error closing socket");
			}
		}
	}
}